<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>表单验证</title>
	<style>
		*{
			margin: 0;
			padding: 0;
		}
	</style>
</head>
<body>
<a href="#">表单验证</a>


<script>
	var emailcheck = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/;
	// var emailcheck2 = new RegExp(/^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+)+$/);
	var phonecheck = /^1[3|4|5|7|8][0-9]{9}$/;
	var telcheck = /^(0\d{2,3}-\d{7,8})(-\d{1,4})?$/;
	var numcheck = /^[0-9]$/;
	var engcheck = /^[a-zA-Z]+$/;
	var chincheck = /^[\u4E00-\u9FA5]+$/;
	var xiaoxie = /^[a-z]+$/;
	var daxie = /^[A-Z]+$/;
	function formcheck(str,type){
		switch(type){
			case "email":
			return emailcheck2.test(str);
			case "phone":
			return phonecheck.test(str);
			case "tel":
			return telcheck.test(str);
			case "number":
			return numcheck.test(str);
			case "english":
			return engcheck.test(str);
			case "chinese":
			return chincheck.test(str);
			case "lower":
			return xiaoxie.test(str);
			case "upper":
			return daxie.test(str);
			default: return false;
		}
	}

	console.log(formcheck("====",""));
</script>
</body>
</html>